package com.example.june.zhanghaoguanli;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.longfly_example.e_scale.R;

import java.util.List;

public class Myadapter_xsjl extends BaseAdapter {
    private List<LianxirenBean> myList;//数据源
    private LayoutInflater myInflater;//布局装载器对象

    // 通过构造方法将数据源与数据适配器关联起来
    // context:要使用当前的Adapter的界面对象
    public Myadapter_xsjl(Activity_xsjl context, List<LianxirenBean> list) {
        myList = list;
        myInflater = LayoutInflater.from(context);
    }


    @Override
    //ListView需要显示的数据数量
    public int getCount() {
        return myList.size();
    }

    @Override
    //指定的索引对应的数据项
    public Object getItem(int position) {
        return myList.get(position);
    }

    @Override
    //指定的索引对应的数据项ID
    public long getItemId(int position) {
        return position;
    }

    @Override
    //返回每一项的显示内容
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = myInflater.inflate(R.layout.item_xsjl, parent, false); //加载布局
            holder = new ViewHolder();
            holder.number = (TextView) convertView.findViewById(R.id.number);
            holder.name = (TextView) convertView.findViewById(R.id.name);
            holder.price = (TextView) convertView.findViewById(R.id.price);
            holder.money = (TextView) convertView.findViewById(R.id.money);
            holder.quantity = (TextView) convertView.findViewById(R.id.quantity);
            convertView.setTag(holder);
        }else {   //else里面说明，convertView已经被复用了，说明convertView中已经设置过tag了，即holder
                        holder = (ViewHolder) convertView.getTag();
        }
        LianxirenBean bean = myList.get(position);
        holder.number.setText(bean.getNumber());
        holder.name.setText(bean.getName());
        holder.price.setText(bean.getPrice());
        holder.money.setText(bean.getMeney());
        holder.quantity.setText(bean.getQuantity());

        return convertView;
    }
    private class ViewHolder {
         TextView number;
         TextView name;
         TextView price;
         TextView money;
         TextView quantity;
     }
}
